package com.anyou.mall.goo.goodsSpecs.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.anyou.common.annotation.Log;
import com.anyou.common.core.controller.BaseController;
import com.anyou.common.core.domain.ApiResult;
import com.anyou.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.anyou.mall.goo.goodsSpecs.domain.GooGoodsSpecs;
import com.anyou.mall.goo.goodsSpecs.service.IGooGoodsSpecsService;
import com.anyou.common.utils.poi.ExcelUtil;
import com.anyou.common.core.page.TableDataInfo;

/**
 * 商品规格Controller
 *
 * @author ylj
 * @date 2022-03-29
 */
@Api(tags = "商品规格")
@RestController
@RequestMapping("/goodsSpecs/goodsSpecs")
public class GooGoodsSpecsController extends BaseController
{
    @Autowired
    private IGooGoodsSpecsService gooGoodsSpecsService;

    /**
     * 查询商品规格列表
     */
    @ApiOperation("查询商品规格列表")
    @PreAuthorize("@ss.hasPermi('goodsSpecs:goodsSpecs:list')")
    @GetMapping("/list")
    public TableDataInfo<List<GooGoodsSpecs>> list(GooGoodsSpecs gooGoodsSpecs)
    {
        startPage();
        List<GooGoodsSpecs> list = gooGoodsSpecsService.selectGooGoodsSpecsList(gooGoodsSpecs);
        return getDataTable(list);
    }

    /**
     * 导出商品规格列表
     */
    @ApiOperation("导出商品规格列表")
    @PreAuthorize("@ss.hasPermi('goodsSpecs:goodsSpecs:export')")
    @Log(title = "商品规格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GooGoodsSpecs gooGoodsSpecs)
    {
        List<GooGoodsSpecs> list = gooGoodsSpecsService.selectGooGoodsSpecsList(gooGoodsSpecs);
        ExcelUtil<GooGoodsSpecs> util = new ExcelUtil<GooGoodsSpecs>(GooGoodsSpecs.class);
        util.exportExcel(response, list, "商品规格数据");
    }

    /**
     * 获取商品规格详细信息
     */
    @ApiOperation("获取商品规格详细信息")
    @PreAuthorize("@ss.hasPermi('goodsSpecs:goodsSpecs:query')")
    @GetMapping(value = "/{goodsSpecsId}")
    public ApiResult<GooGoodsSpecs> getInfo(@PathVariable("goodsSpecsId") Long goodsSpecsId)
    {
        return ApiResult.success(gooGoodsSpecsService.selectGooGoodsSpecsByGoodsSpecsId(goodsSpecsId));
    }

    /**
     * 新增商品规格
     */
    @ApiOperation("新增商品规格")
    @PreAuthorize("@ss.hasPermi('goodsSpecs:goodsSpecs:add')")
    @Log(title = "商品规格", businessType = BusinessType.INSERT)
    @PostMapping
    public ApiResult add(@RequestBody GooGoodsSpecs gooGoodsSpecs)
    {
        return ApiResult.success(gooGoodsSpecsService.insertGooGoodsSpecs(gooGoodsSpecs));
    }

    /**
     * 修改商品规格
     */
    @ApiOperation("修改商品规格")
    @PreAuthorize("@ss.hasPermi('goodsSpecs:goodsSpecs:edit')")
    @Log(title = "商品规格", businessType = BusinessType.UPDATE)
    @PutMapping
    public ApiResult edit(@RequestBody GooGoodsSpecs gooGoodsSpecs)
    {
        return ApiResult.success(gooGoodsSpecsService.updateGooGoodsSpecs(gooGoodsSpecs));
    }

    /**
     * 删除商品规格
     */
    @ApiOperation("删除商品规格")
    @PreAuthorize("@ss.hasPermi('goodsSpecs:goodsSpecs:remove')")
    @Log(title = "商品规格", businessType = BusinessType.DELETE)
    @DeleteMapping("/{goodsSpecsIds}")
    public ApiResult remove(@PathVariable Long[] goodsSpecsIds)
    {
        return ApiResult.success(gooGoodsSpecsService.deleteGooGoodsSpecsByGoodsSpecsIds(goodsSpecsIds));
    }
}
